/*
 * @Description: 上传
 * @Author: HuiSir<273250950@qq.com>
 * @Date: 2021-09-24 22:56:35
 * @LastEditTime: 2025-08-13 17:19:16
 */
import { useProjectConfig, rules2MockMethods } from "./_helpers";
import Mockjs from "mockjs";
const project = useProjectConfig();
const { Random } = Mockjs;
const Prefix = "/file/";

// 上传文件
const upload = {
  [project.responseFields.data]: Random.image(
    "200x200",
    Random.color(),
    Random.color(),
    "@ctitle(5, 10).@pick(['jpg', 'png'])"
  ),
  [project.responseFields.message]: "上传成功",
};

// 分頁查文件列表
const getFileListByPage = {
  [project.responseFields.data]: {
    [`${project.responseDataSubFields.records}|15`]: [
      {
        id: "@id",
        position: '@pick(["local", "oss" , "cos" , "kodo"])',
        name: "@ctitle(3, 5)",
        size: "@integer(1024, 999999)",
        width() {
          if (this.url.includes("jpg")) return Random.integer(60, 100);
          else return null;
        },
        height() {
          if (this.url.includes("jpg")) return Random.integer(60, 100);
          else return null;
        },
        remark: "@cparagraph(1, 3)",
        group: '@pick(["icon", "goodsImg" , "banner" , "document"])',
        url: Random.image(
          "64x64",
          Random.color(),
          Random.color(),
          "@ctitle(5, 10).@pick(['jpg','docx','zip','pdf','xml','xlsx'])"
        ),
        createTime: "@datetime",
        updateTime: "@datetime",
        createUser: "@string('lower', 5)",
        updateUser: "@string('lower', 5)",
      },
    ],
    page: 1,
    limit: 15,
    [project.responseDataSubFields.total]: 100,
    pageSize: 15,
  },
};

// 删除文件
const removeFileById = { [project.responseFields.message]: "删除成功" };

// 查询类目列表
const getFileGroupList = {
  [project.responseFields.data]: [
    {
      id: "@id",
      name: "icon",
    },
    {
      id: "@id",
      name: "goodsImg",
    },
    {
      id: "@id",
      name: "banner",
    },
    {
      id: "@id",
      name: "document",
    },
  ],
};

// 新增类目
const addFileGroup = {
  [project.responseFields.data]: {
    id: "@id",
    name: "@ctitle(3, 5)",
  },
  [project.responseFields.message]: "新增成功",
};

// 保存文件信息
const update = { [project.responseFields.message]: "保存成功" };

const Rules: Record<string, unknown> = {
  upload,
  getFileListByPage,
  removeFileById,
  getFileGroupList,
  addFileGroup,
  update,
};

export default rules2MockMethods(Rules, Prefix);
